package router

import (
	"url_shorten/common/middleware"
	"url_shorten/internal/service"

	"github.com/gin-gonic/gin"

	_ "url_shorten/docs" // swag init 产生的 docs

	swaggerfiles "github.com/swaggo/files"
	ginSwagger "github.com/swaggo/gin-swagger"
)

func Router() *gin.Engine {
	// r := gin.Default()
	r := gin.New()
	r.Use(gin.Recovery())
	r.Use(middleware.CorsMiddleware(), middleware.GinLogMiddleware())
	// 配置路由

	r.GET("/swagger-ui/*any", ginSwagger.WrapHandler(swaggerfiles.Handler))
	// r.GET("/ping", middleware.AuthMiddleware(), service.PingServer)
	r.GET("/ping", service.PingServer)

	r.POST("/api/shorten", service.ShortenUrlGet)
	r.GET("/:shorten_code", service.ShortenRedirect)
	r.GET("/api/statistics/:shorten_code", service.ShortenStatisticsByCode)
	r.GET("/api/statistics", service.ShortenStatistics)
	
	return r
}
